# —————————— 第1种方式 ——————————
# import requests
# headers = {
#     'Cookie': 'E716F6BBACF9ED9DFF0D795FF48D513D:FG=1',      # 设置字段Cookie
#     'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4)' 
#                   'AppleWebKit/537.36 (KHTML, like Gecko)'   
#                   'Chrome/53.0.2785.116 Safari/537.36',} # 设置字段User-Agent
# response = requests.get('https://www.baidu.com/', headers=headers)
# print(response.text)


# # —————————— 第2种方式 ——————————
import requests
header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) '
                        'AppleWebKit/537.36 (KHTML, like Gecko)' 
                        'Chrome/53.0.2785.116 Safari/537.36'}
# 准备Cookie
cookie = 'E716F6BBACF9ED9DFF0D795FF48D513D:FG=1'
# 创建RequestsCookieJar类对象
jar_obj = requests.cookies.RequestsCookieJar()
# 以逗号为分隔符分割cookie，并将获得的键和值保存至jar_obj中
for temp in cookie.split(';'):
    key, value = temp.split('=', 1)
    jar_obj.set(key, value)
response = requests.get('https://www.baidu.com/', headers=header, cookies=jar_obj)
print(response.text)
